package com.firefly.mobile.app.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import com.firefly.mobile.app.context.SytApplication;


/**
 */
public class PropertyFileUtil {

	/** 流水号属性对象 */
	private static Properties prop = new Properties();
	
	public static String TRANS_FILE_PATH = null;
	

	
	public static String readCityCode(){
		if ("".equals(TRANS_FILE_PATH) || TRANS_FILE_PATH == null) {
			TRANS_FILE_PATH = SytApplication.getSdcardFilePath() + File.separator+"conf"+File.separator+"city.property";
		}
		String last = "289";
		FileInputStream is = null;
		try {
			File file = new File(TRANS_FILE_PATH);
			
			if (file.exists()) {
			}else {
				File parent = new File(file.getParent());
				parent.mkdirs();
				file.createNewFile();
			}
			is = new FileInputStream(file);
			prop.load(is);
			
			
			Object obj = prop.get("cityInfo");
			if(obj!=null){
				return obj.toString();
			}
		} catch (Exception e) {
			
			SytLog.i("读取"+TRANS_FILE_PATH+"文件异常："+e.toString());
			
		}finally{
			if(is!=null){
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return last;
		
	}
	
	

	public static void writeLast(String last) {
		FileOutputStream os = null;
		try {
			File file = new File(TRANS_FILE_PATH);
			
			if (!file.exists()) {
				File parent = new File(file.getParent());
				parent.mkdirs();
				file.createNewFile();
			}
			
			os = new FileOutputStream(TRANS_FILE_PATH);
			prop.setProperty("cityInfo", last);
			prop.store(os, null);
		} catch (Exception e) {
			SytLog.i("写入"+TRANS_FILE_PATH+"文件异常："+e.toString());
			e.printStackTrace();
		}finally{
			if(os!=null){
				try {
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
